package com.laihui.fragment;


import android.app.Activity;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.laihui.MyApplication;
import com.laihui.activity.R;
import com.laihui.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 我的投资页面
 */
public class Index2Fragment extends BaseFragment {


    @BindView(R.id.tabs)
    TabLayout tabs;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    private Activity mActivity;
    private MyApplication application;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private List<String> mTitles = new ArrayList<>();


    @Override
    public void init() {

        initViewPager();
    }

    private ArrayList<Fragment> getFragments() {
        ArrayList<Fragment> list = new ArrayList<>();
        list.add(new BorrowListFragment(null));
        list.add(new BorrowListFragment(1));
        list.add(new BorrowListFragment(2));
        list.add(new BorrowListFragment(8));
        return list;
    }


    private class BorrowPagerAdapter extends FragmentPagerAdapter {

        public BorrowPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles.get(position);
        }
    }

    private void initViewPager() {
        mFragments = getFragments();
        mTitles.add("全部");
        mTitles.add("新手标");
        mTitles.add("月标");
        mTitles.add("约标");
        viewPager.setAdapter(new BorrowPagerAdapter(getActivity().getSupportFragmentManager()));
        viewPager.setOffscreenPageLimit(4);
        tabs.setupWithViewPager(viewPager);
    }

    @Override
    public int getFragmentId() {
        return R.layout.fragment_index2;

    }

    @Override
    public Object bindFragment() {
        return this;

    }
}
